#coding=utf-8
from handle.register_handle import RegisterHandle
class RegisterBusiness:
    def __init__(self,driver):
        self.register_h = RegisterHandle(driver)

    def user_base(self,name,code,password_1,password_2):
        # self.register_h.send_user_email(email)
        self.register_h.send_user_name(name)
        self.register_h.send_user_code(code)
        self.register_h.send_user_password(password_1)
        self.register_h.send_user_password_2(password_2)
        # self.register_h.send_user_code(file_name)
        self.register_h.click_register_button()
    
    def register_succes(self):
        if self.register_h.get_register_text() == None:
            return True
        else:
            return False

    #执行操作
    def login_email_error(self,email,name,password,file_name):
        self.user_base(email,name,password,file_name)   
        if self.register_h.get_user_text('email_error',"请输入有效的电子邮件地址") == None:
            #print("邮箱检验不成功")
            return True
        else:
            return False
        
    def register_function(self,username,code,password_1,password_2,assertCode,assertText):
        self.user_base(username,code,password_1,password_2)
        a01 = self.register_h.get_user_text(assertCode, assertText)
        if a01 == None:
            #print("邮箱检验不成功")
            result = 'assertCode--断言的元素不存在！'
        else:
            return a01
    #name错误
    def login_name_error(self,email,name,password,file_name):
        self.user_base(email,name,password,file_name)
        if self.register_h.get_user_text('user_name_error',"字符长度必须大于等于4，一个中文字算2个字符") == None:
            #print("用户名检验不成功")
            return True
        else:
            return False
    
    #密码错误
    def login_password_error(self,email,name,password,file_name):
        self.user_base(email,name,password,file_name)
        if self.register_h.get_user_text('password_error',"最少需要输入 5 个字符") == None:
            #print("密码检验不成功")
            return True
        else:
            return False

    #验证码错误
    def login_code_error(self,email,name,password,file_name):
        self.user_base(email,name,password,file_name)
        if self.register_h.get_user_text('code_text_error',"验证码错误") == None:
            #print("验证码检验不成功")
            return True
        else:
            return False
        